import numpy as np
import matplotlib.pyplot as plt

def sigmoid(x):
    return 1 / (1 + np.exp(-x))

def sigmoid_derivative(x):
    return sigmoid(x) * (1 - sigmoid(x))

# 测试不同权重范围对梯度的影响
x = 1.0  # 假设输入值
weight_ranges = [1.0, 0.1, 0.01]
results = []

for scale in weight_ranges:
    weights = np.random.randn(1000) * scale  # 生成1000个不同权重的样本
    z = x * weights  # 加权输入
    gradients = sigmoid_derivative(z)  # 计算梯度
    
    results.append({
        'scale': scale,
        'mean_gradient': np.mean(gradients),
        'std_gradient': np.std(gradients),
        'saturated_ratio': np.mean(gradients < 0.01)  # 梯度接近0的比例
    })

# 显示结果
for res in results:
    print(f"缩放因子: {res['scale']:.3f}, "
          f"平均梯度: {res['mean_gradient']:.4f}, "
          f"饱和比例: {res['saturated_ratio']:.2%}")